cmake_minimum_required(VERSION 2.8)
project(nanorpc)

add_compile_options(-std=c++11)
add_compile_options(-pthread)

file(GLOB_RECURSE SOURCE_FILES src/yolo.cpp)
# file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
# file(GLOB_RECURSE SOURCE_FILES1 src/*.cc)
# file(GLOB_RECURSE HEADER_FILES include/*.h)
# message("${SOURCE_FILES1}")
include_directories(
    ${CMAKE_CURRENT_LIST_DIR}/../${PROJECT_NAME}/include    
    ${CMAKE_CURRENT_LIST_DIR}/../darknet/include    
    ${CMAKE_CURRENT_BINARY_DIR}    
)

find_package(OpenCV REQUIRED)


find_package(Protobuf REQUIRED)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS proto/echo.proto)

# add_library(${PROJECT_NAME} SHARED 
# ${PROTO_SRCS} 
# ${PROTO_HDRS}
# ${SOURCE_FILES}
# ${SOURCE_FILES1}
# ${HEADER_FILES}
# )

# target_link_libraries(${PROJECT_NAME} 
# ${PROTOBUF_LIBRARIES} 
# nanomsg
# )






add_library(yolo_plugin

    ${SOURCE_FILES}
)


# target_link_libraries(yolo_plugin
#     darknet
# )

file(GLOB_RECURSE HEADER_FILES include/*.h)
foreach(type server client)
    file(GLOB_RECURSE ${type}_FILES ${type}/*.cc)
    add_executable(${PROJECT_NAME}_${type}
      ${${type}_FILES}
      ${PROTO_SRCS} 
        ${PROTO_HDRS}
      ${HEADER_FILES}
    )


    target_link_libraries(${PROJECT_NAME}_${type}
        ${PROTOBUF_LIBRARIES} 
        nanomsg
        cityhash

        yolo_plugin
        darknet

        ${OpenCV_LIBS}
        pthread
    )

    install(TARGETS ${PROJECT_NAME}_${type}
            DESTINATION lib
            )
endforeach()


# add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
#                    COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h ${CMAKE_CURRENT_BINARY_DIR})
# add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
#                    COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/include)

# install(TARGETS ${PROJECT_NAME}
#         DESTINATION lib
#         )
# install(DIRECTORY include/
#         DESTINATION include)